//
//  MyFavoritesModel.m
//
//  Created by mac  on 2018/12/5
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "MyFavoritesModel.h"


NSString *const kMyFavoritesModelArticleType = @"ArticleType";
NSString *const kMyFavoritesModelCode = @"Code";
NSString *const kMyFavoritesModelAuthorCode = @"AuthorCode";
NSString *const kMyFavoritesModelPicNum = @"PicNum";
NSString *const kMyFavoritesModelTitle = @"Title";
NSString *const kMyFavoritesModelCoverPic = @"CoverPic";
NSString *const kMyFavoritesModelArticleTypeDesc = @"ArticleTypeDesc";
NSString *const kMyFavoritesModelAuthorNickName = @"AuthorNickName";
NSString *const kMyFavoritesModelCommentNum = @"CommentNum";
NSString *const kMyFavoritesModelViewTimes = @"ViewTimes";
NSString *const kMyFavoritesModelAbstract = @"Abstract";
NSString *const kMyFavoritesModelTopicalName = @"TopicalName";
NSString *const kMyFavoritesModelID = @"ID";
NSString *const kMyFavoritesModelAuthorID = @"AuthorID";
NSString *const kMyFavoritesModelIssueDate = @"IssueDate";
NSString *const kMyFavoritesModelGoodNum = @"GoodNum";
NSString *const kMyFavoritesModelPageViewType = @"PageViewType";
NSString *const kMyFavoritesModelVideoUrl = @"VideoUrl";
NSString *const kMyFavoritesModelCheckDate = @"CheckDate";
NSString *const kMyFavoritesModelTopicalID = @"TopicalID";


@interface MyFavoritesModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation MyFavoritesModel

@synthesize articleType = _articleType;
@synthesize code = _code;
@synthesize authorCode = _authorCode;
@synthesize picNum = _picNum;
@synthesize title = _title;
@synthesize coverPic = _coverPic;
@synthesize articleTypeDesc = _articleTypeDesc;
@synthesize authorNickName = _authorNickName;
@synthesize commentNum = _commentNum;
@synthesize viewTimes = _viewTimes;
@synthesize abstract = _abstract;
@synthesize topicalName = _topicalName;
@synthesize iDProperty = _iDProperty;
@synthesize authorID = _authorID;
@synthesize issueDate = _issueDate;
@synthesize goodNum = _goodNum;
@synthesize pageViewType = _pageViewType;
@synthesize videoUrl = _videoUrl;
@synthesize checkDate = _checkDate;
@synthesize topicalID = _topicalID;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.articleType = [[self objectOrNilForKey:kMyFavoritesModelArticleType fromDictionary:dict] doubleValue];
            self.code = [self objectOrNilForKey:kMyFavoritesModelCode fromDictionary:dict];
            self.authorCode = [self objectOrNilForKey:kMyFavoritesModelAuthorCode fromDictionary:dict];
            self.picNum = [[self objectOrNilForKey:kMyFavoritesModelPicNum fromDictionary:dict] doubleValue];
            self.title = [self objectOrNilForKey:kMyFavoritesModelTitle fromDictionary:dict];
            self.coverPic = [self objectOrNilForKey:kMyFavoritesModelCoverPic fromDictionary:dict];
            self.articleTypeDesc = [self objectOrNilForKey:kMyFavoritesModelArticleTypeDesc fromDictionary:dict];
            self.authorNickName = [self objectOrNilForKey:kMyFavoritesModelAuthorNickName fromDictionary:dict];
            self.commentNum = [[self objectOrNilForKey:kMyFavoritesModelCommentNum fromDictionary:dict] doubleValue];
            self.viewTimes = [[self objectOrNilForKey:kMyFavoritesModelViewTimes fromDictionary:dict] doubleValue];
            self.abstract = [self objectOrNilForKey:kMyFavoritesModelAbstract fromDictionary:dict];
            self.topicalName = [self objectOrNilForKey:kMyFavoritesModelTopicalName fromDictionary:dict];
            self.iDProperty = [[self objectOrNilForKey:kMyFavoritesModelID fromDictionary:dict] doubleValue];
            self.authorID = [[self objectOrNilForKey:kMyFavoritesModelAuthorID fromDictionary:dict] intValue];
            self.issueDate = [self objectOrNilForKey:kMyFavoritesModelIssueDate fromDictionary:dict];
            self.goodNum = [[self objectOrNilForKey:kMyFavoritesModelGoodNum fromDictionary:dict] doubleValue];
            self.pageViewType = [[self objectOrNilForKey:kMyFavoritesModelPageViewType fromDictionary:dict] doubleValue];
            self.videoUrl = [self objectOrNilForKey:kMyFavoritesModelVideoUrl fromDictionary:dict];
            self.checkDate = [self objectOrNilForKey:kMyFavoritesModelCheckDate fromDictionary:dict];
            self.topicalID = [[self objectOrNilForKey:kMyFavoritesModelTopicalID fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.articleType] forKey:kMyFavoritesModelArticleType];
    [mutableDict setValue:self.code forKey:kMyFavoritesModelCode];
    [mutableDict setValue:self.authorCode forKey:kMyFavoritesModelAuthorCode];
    [mutableDict setValue:[NSNumber numberWithDouble:self.picNum] forKey:kMyFavoritesModelPicNum];
    [mutableDict setValue:self.title forKey:kMyFavoritesModelTitle];
    [mutableDict setValue:self.coverPic forKey:kMyFavoritesModelCoverPic];
    [mutableDict setValue:self.articleTypeDesc forKey:kMyFavoritesModelArticleTypeDesc];
    [mutableDict setValue:self.authorNickName forKey:kMyFavoritesModelAuthorNickName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.commentNum] forKey:kMyFavoritesModelCommentNum];
    [mutableDict setValue:[NSNumber numberWithDouble:self.viewTimes] forKey:kMyFavoritesModelViewTimes];
    [mutableDict setValue:self.abstract forKey:kMyFavoritesModelAbstract];
    [mutableDict setValue:self.topicalName forKey:kMyFavoritesModelTopicalName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.iDProperty] forKey:kMyFavoritesModelID];
    [mutableDict setValue:[NSNumber numberWithInt:self.authorID] forKey:kMyFavoritesModelAuthorID];
    [mutableDict setValue:self.issueDate forKey:kMyFavoritesModelIssueDate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.goodNum] forKey:kMyFavoritesModelGoodNum];
    [mutableDict setValue:[NSNumber numberWithDouble:self.pageViewType] forKey:kMyFavoritesModelPageViewType];
    [mutableDict setValue:self.videoUrl forKey:kMyFavoritesModelVideoUrl];
    [mutableDict setValue:self.checkDate forKey:kMyFavoritesModelCheckDate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.topicalID] forKey:kMyFavoritesModelTopicalID];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.articleType = [aDecoder decodeDoubleForKey:kMyFavoritesModelArticleType];
    self.code = [aDecoder decodeObjectForKey:kMyFavoritesModelCode];
    self.authorCode = [aDecoder decodeObjectForKey:kMyFavoritesModelAuthorCode];
    self.picNum = [aDecoder decodeDoubleForKey:kMyFavoritesModelPicNum];
    self.title = [aDecoder decodeObjectForKey:kMyFavoritesModelTitle];
    self.coverPic = [aDecoder decodeObjectForKey:kMyFavoritesModelCoverPic];
    self.articleTypeDesc = [aDecoder decodeObjectForKey:kMyFavoritesModelArticleTypeDesc];
    self.authorNickName = [aDecoder decodeObjectForKey:kMyFavoritesModelAuthorNickName];
    self.commentNum = [aDecoder decodeDoubleForKey:kMyFavoritesModelCommentNum];
    self.viewTimes = [aDecoder decodeDoubleForKey:kMyFavoritesModelViewTimes];
    self.abstract = [aDecoder decodeObjectForKey:kMyFavoritesModelAbstract];
    self.topicalName = [aDecoder decodeObjectForKey:kMyFavoritesModelTopicalName];
    self.iDProperty = [aDecoder decodeDoubleForKey:kMyFavoritesModelID];
    self.authorID = [aDecoder decodeIntegerForKey:kMyFavoritesModelAuthorID];
    self.issueDate = [aDecoder decodeObjectForKey:kMyFavoritesModelIssueDate];
    self.goodNum = [aDecoder decodeDoubleForKey:kMyFavoritesModelGoodNum];
    self.pageViewType = [aDecoder decodeDoubleForKey:kMyFavoritesModelPageViewType];
    self.videoUrl = [aDecoder decodeObjectForKey:kMyFavoritesModelVideoUrl];
    self.checkDate = [aDecoder decodeObjectForKey:kMyFavoritesModelCheckDate];
    self.topicalID = [aDecoder decodeDoubleForKey:kMyFavoritesModelTopicalID];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_articleType forKey:kMyFavoritesModelArticleType];
    [aCoder encodeObject:_code forKey:kMyFavoritesModelCode];
    [aCoder encodeObject:_authorCode forKey:kMyFavoritesModelAuthorCode];
    [aCoder encodeDouble:_picNum forKey:kMyFavoritesModelPicNum];
    [aCoder encodeObject:_title forKey:kMyFavoritesModelTitle];
    [aCoder encodeObject:_coverPic forKey:kMyFavoritesModelCoverPic];
    [aCoder encodeObject:_articleTypeDesc forKey:kMyFavoritesModelArticleTypeDesc];
    [aCoder encodeObject:_authorNickName forKey:kMyFavoritesModelAuthorNickName];
    [aCoder encodeDouble:_commentNum forKey:kMyFavoritesModelCommentNum];
    [aCoder encodeDouble:_viewTimes forKey:kMyFavoritesModelViewTimes];
    [aCoder encodeObject:_abstract forKey:kMyFavoritesModelAbstract];
    [aCoder encodeObject:_topicalName forKey:kMyFavoritesModelTopicalName];
    [aCoder encodeDouble:_iDProperty forKey:kMyFavoritesModelID];
    [aCoder encodeInteger:_authorID forKey:kMyFavoritesModelAuthorID];
    [aCoder encodeObject:_issueDate forKey:kMyFavoritesModelIssueDate];
    [aCoder encodeDouble:_goodNum forKey:kMyFavoritesModelGoodNum];
    [aCoder encodeDouble:_pageViewType forKey:kMyFavoritesModelPageViewType];
    [aCoder encodeObject:_videoUrl forKey:kMyFavoritesModelVideoUrl];
    [aCoder encodeObject:_checkDate forKey:kMyFavoritesModelCheckDate];
    [aCoder encodeDouble:_topicalID forKey:kMyFavoritesModelTopicalID];
}

- (id)copyWithZone:(NSZone *)zone
{
    MyFavoritesModel *copy = [[MyFavoritesModel alloc] init];
    
    if (copy) {

        copy.articleType = self.articleType;
        copy.code = [self.code copyWithZone:zone];
        copy.authorCode = [self.authorCode copyWithZone:zone];
        copy.picNum = self.picNum;
        copy.title = [self.title copyWithZone:zone];
        copy.coverPic = [self.coverPic copyWithZone:zone];
        copy.articleTypeDesc = [self.articleTypeDesc copyWithZone:zone];
        copy.authorNickName = [self.authorNickName copyWithZone:zone];
        copy.commentNum = self.commentNum;
        copy.viewTimes = self.viewTimes;
        copy.abstract = [self.abstract copyWithZone:zone];
        copy.topicalName = [self.topicalName copyWithZone:zone];
        copy.iDProperty = self.iDProperty;
        copy.authorID = self.authorID;
        copy.issueDate = [self.issueDate copyWithZone:zone];
        copy.goodNum = self.goodNum;
        copy.pageViewType = self.pageViewType;
        copy.videoUrl = [self.videoUrl copyWithZone:zone];
        copy.checkDate = [self.checkDate copyWithZone:zone];
        copy.topicalID = self.topicalID;
    }
    
    return copy;
}


@end
